﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CantinhodaCegonha.Models.Helpers;
using System.Data.Entity;
using Data;
using System.Globalization;

namespace CantinhodaCegonha
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("elmah.axd");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            routes.MapRoute(
                 "Activate",
                 "Account/Activate/{username}/{key}",
                 new{controller = "Account",action = "Activate",username = UrlParameter.Optional,key = UrlParameter.Optional
                 });

            routes.MapRoute(
                    "Comunidade", // Route name
                    "Comunidade", // URL with parameters
                    new { controller = "Pergunta", action = "Index" } // Parameter defaults
                );

            routes.MapRoute(
                "Artigos", // Route name
                "Artigo/{nome}", // URL with parameters
                new { controller = "Artigo", action = "Details" } // Parameter defaults
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-PT");
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-PT");

            AjaxHelper.GlobalizationScriptPath ="http://ajax.microsoft.com/ajax/4.0/1/globalization/";
            

            AreaRegistration.RegisterAllAreas();

            //Database.SetInitializer<MyCantinhoContext>(new MyCantinhoContextInitializer());

            ModelBinders.Binders.Add(typeof(DateTime), new DateTimeModelBinder());
            ModelBinders.Binders.Add(typeof(DateTime?), new NullDateTimeModelBinder());
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}